<!DOCTYPE html>
<html>

	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<meta name="format-detection" content="telephone=no" />
		<meta charset="utf-8">
		<title>购物车</title>
		<!--字体图标库-->
		<link rel="stylesheet" href="__TPL__/team/css/ectouch.css" />

	</head>

	<body>
		<!-- {if $goods_list } -->
		<div class="con">
			<div id="loading"><img src="__TPL__/team/images/loading.gif" /></div>
			<div class="flow-pb">
				<header class="flow-cart-header position-rel" style="display:none">
					<a href="{:url('index/index')}"><span class="flow-tag">包邮</span> 全场满99元包邮，还差20.80元
						<span class="fr col-9">去凑单<i class="iconfont icon-mn-jiantour font-03"></i></span>
					</a>
				</header>
				<section class="flow-cart blur-div flow-no-cart flow-have-cart select-three j-select-all fresh-flow-list">
					<ul class="goods-shop-pic j-index-sum j-get-i-more b-color-f product-list-small">
						<!-- {foreach from=$goods_list item=goods key=k} -->
						<li>
							<div class="dis-box flow-list-box">
								<div class="ect-select js-ect-select">
									<label class="rec-active <!-- {if $goods.is_selected eq 1}-->active<!-- {/if}-->" goods-id="{$goods.goods_id}"  rec-id="{$goods.rec_id}"><i class="j-select-btn"></i></label>
								</div>
								<div class="box-flex">
									<div style="display:none" class="flow-cart-tag font-03 col-9 m-top04"><span class="flow-list-tag">满赠</span>满30元可获得赠品一件<span class="fr"><i class="iconfont icon-mn-jiantour font-03"></i></sapn></div>
									<ul class="product-div dis-box">
										<a href="{:url('goods/index',array('id'=>$this->_var['goods']['goods_id']))}">
											<div class="goods-list-detail">
												<img src="{$goods.goods_thumb}">
											</div>
										</a>
										<div class="box-flex catalog-cont flow-cont-list">
											<a href="{:url('goods/index',array('id'=>$this->_var['goods']['goods_id']))}">
												<h5 class="text-l ec-titc font-05 onelist-hidden">{$goods.goods_name} </h5>
												<!-- {if $show_goods_attribute eq 1} 显示商品属性 -->
												<p class="text-l ec-conc font-03 m-top02">{$goods.goods_attr|nl2br}</p>
												<!-- {/if} -->
											</a>
									
												<div class=" m-top02 ec-color">{$goods.goods_price}</div>								
												<div class="div-num dis-box m-top08">
														<a class="num-less" onClick="change_goods_number('1',{$goods.rec_id})"></a>
														<input type="hidden" id="back_number{$goods.rec_id}" value="{$goods.goods_number}" />
														<input class="box-flex" type="number" name="{$goods.rec_id}" id="goods_number{$goods.rec_id}" value="{$goods.goods_number}" onblur="change_goods_number('2',{$goods.rec_id})">
														<a class="num-plus" onClick="change_goods_number('3',{$goods.rec_id})"></a>
												</div>								
										
										</div>
									</ul>
									<ul class="product-div dis-box bd-t" style="display:none">
										<a href="{:url('goods/index',array('id'=>$this->_var['goods']['goods_id']))}">
											<div class="goods-list-detail">
												<img src="__TPL__/team/images/cate-4.jpg">
												<span class="gifts-tag">赠品</span>
											</div>
										</a>
										<div class="box-flex catalog-cont flow-cont-list">
											<a href="goods.html">
												<h5 class="text-l ec-titc font-05 onelist-hidden">新鲜蓝莓鲜果125g优等果</h5>
												<p class="text-l ec-conc font-03 m-top02">12枚每盒 约2.5kg</p>
											</a>
											<div class="dis-box m-top10">
												<div class="box-flex m-top08 ec-color">¥120.00</div>												
											</div>
										</div>
									</ul>
								</div>
							</div>
						</li>
						<!-- {/foreach} -->
						
					</ul>
				</section>
			</div>
		</div>
		<!--悬浮btn star-->
		<section class="folw-fixed-footer">
			<section class="filter-btn-pos f-cart-filter-btn position-rel dis-box pos-sta maxbox">
				<div class="box-flex select-three j-get-more j-get-more-all flow-footer-left">
					<div class="ect-select">
						<label class="dis-box label-all ">
							<i class="select-btn"></i>
							<span class="box-flex">全选</span></span>
						</label>
					</div>
					<div class="g-cart-filter-price of-hidden">
						<p class="dis-box"><em class="dis-block">合计：</em><span class="ec-color box-flex onelist-hidden" id="goods_subtotal">{$total.goods_price}</span></p>
						<p class="font-03 col-9">不含运费</p>
					</div>
				</div>
				<div class="g-cart-filter-sb">
					<span class="span-bianji fl"><i class="iconfont icon-evaluation"></i><em>编辑</em></span>
					<a onclick="c_value()" type="button" class="btn-submit font-07 fl" >结算 <b id="total_number">({$total.total_number})</b></a>
				</div>
				<div class="g-cart-filter-bj">
					<span class="heart j-heart fl" style="display:none"><i class="ts-2"></i><em class="ts-2">关注</em></span>
					<a type="button" class="btn-default j-btn-default font-07 fl">返回</a>
					<a type="button" class="btn-submit font-07 fl" onclick="remove_goods()">删除</a>
				</div>
			</section>
			<footer class="footer-nav dis-box flow-footer">
				<a href="{:url('index/index')}" class="box-flex nav-list">
					<i class="nav-box i-home"></i><span>首页</span>
				</a>
				<a href="{:url('category/top_all')}" class="box-flex nav-list">
						<i class="nav-box i-cate"></i><span>分类</span>
					</a>
				<a href="{:url('category/user_ranking')}" class="box-flex nav-list">
					<i class="nav-box i-ranking"></i><span>排行</span>
				</a>
				<a href="{:url('flow/cart')}" class="box-flex position-rel nav-list active">
					<i class="nav-box i-flow"></i><span>购物车</span>
					<em class="position-abo ect-num-tag">10</em>
				</a>
				<a href="{:url('user/index')}" class="box-flex nav-list">
					<i class="nav-box i-user"></i><span>用户中心</span>
				</a>
			</footer>
		</section>
		<!--{else}-->
			<section class="flow-no-cart">
				<span class="gwc-bg">
						<i class="iconfont icon-cart "></i>
					</span>
				<p class="col-7 font-06 text-c m-top12">购物车什么也没有</p>
				<a href="{:url('index/index')}" type="button" class="btn-f b-s btn-default">去逛逛</a>
			</section>
		<!-- {/if} -->
		
		
		<!--引用js-->
		<script type="text/javascript" src="__TPL__/team/js/jquery-2.1.4.min.js"></script>
		<script type="text/javascript" src="__TPL__/team/js/swiper.min.js"></script>
		<script type="text/javascript" src="__TPL__/team/js/ectouch.js"></script>

		<script>
		function back_goods_number(id){
		 var goods_number = document.getElementById('goods_number'+id).value;
		  document.getElementById('back_number'+id).value = goods_number;
		}
		function change_goods_number(type, id)
		{
		  var goods_number = document.getElementById('goods_number'+id).value;
		  if(type != 2){  back_goods_number(id) }
		  if(type == 1){  goods_number--;  }
		  if(type == 3){  goods_number++;  }
		  if(goods_number <=0 ){ goods_number=1; }
		  if(!/^[0-9]*$/.test(goods_number)){ goods_number = document.getElementById('back_number'+id).value; }
		  document.getElementById('goods_number'+id).value = goods_number;
			$.post('{:url("flow/ajax_update_cart")}', {
				rec_id : id,goods_number : goods_number
			}, function(data) {
				change_goods_number_response(data,id);
			}, 'json');
		}
		// 处理返回信息并显示
		function change_goods_number_response(result,id)
		{
			if (result.error == 0){
				var rec_id = result.rec_id;
				$("#goods_number_"+rec_id).val(result.goods_number);
				document.getElementById('total_number').innerHTML = result.total_number;//更新数量
				document.getElementById('goods_subtotal').innerHTML = result.total_desc;//更新小计
				if (document.getElementById('ECS_CARTINFO')){
					//更新购物车数量
					document.getElementById('ECS_CARTINFO').innerHTML = result.cart_info;
				}
			}else if (result.message != ''){
				alert(result.message);
				var goods_number = document.getElementById('back_number'+id).value;
				document.getElementById('goods_number'+id).value = goods_number;
			}
		}
		
		// 计算选中商品价格数量
		$(".js-ect-select").click(function() {
		var id='';
		$("label").each(function (){
			if($(this).hasClass("rec-active")){
				if($(this).hasClass("active")) {
					id += $(this).attr("rec-id") + ',';
				}
			}
		 })
		 id = id.substr(0,id.length-1);
		 $.ajax({
			type: "POST",
			url: "index.php?m=default&c=flow&a=cart_label_count",
			data: {rec_id:id},
			dataType:"json",
			success: function(data){			
			document.getElementById('total_number').innerHTML = data.cart_number;//更新数量
			document.getElementById('goods_subtotal').innerHTML =data.content;//更新小计	
			}});
		});
		/*多选按钮*/
		$(".j-get-more ").click(function() {
			if(!$(this).find("label").hasClass("active")) {
				$(this).find("label").addClass("active");
				if($(this).find("label").hasClass("label-all")) {
					$(".j-select-all").find(".ect-select label").addClass("active");
				}
			} else {
				$(this).find("label").removeClass("active");
				if($(this).find("label").hasClass("label-all")) {
					$(".j-select-all").find(".ect-select label").removeClass("active");
				}
			}
			var id='';
			$("label").each(function (){
				if($(this).hasClass("rec-active")){
					if($(this).hasClass("active")) {
						id += $(this).attr("rec-id") + ',';
					}
				}
			 })
			 id = id.substr(0,id.length-1);
			 $.ajax({
				type: "POST",
				url: "index.php?m=default&c=flow&a=cart_label_count",
				data: {rec_id:id},
				dataType:"json",
				success: function(data){			
				document.getElementById('total_number').innerHTML = data.cart_number;//更新数量
				document.getElementById('goods_subtotal').innerHTML =data.content;//更新小计	
				}});
		});
		
		//删除选中商品
		function remove_goods(){
			var id='';
			$("label").each(function (){
				if($(this).hasClass("rec-active")){
					if($(this).hasClass("active")) {
						id += $(this).attr("rec-id") + ',';
					}
				}
			 })
			if(id==''){
				alert('请选中删除的商品');
				return false;
			}
			id = id.substr(0,id.length-1);
			$.ajax({
			type: "POST",
			url: "index.php?m=default&c=flow&a=drop_goods",
			data: {rec_id:id},
			dataType:"json",
			success: function(data){			
				if (data.error == 1)
					{
						location.href = 'index.php?c=flow&a=cart';						
					}
			}});
		}
		
		//验证是否选中商品
		function c_value(){
			var id='';
			$("label").each(function (){
				if($(this).hasClass("rec-active")){
					if($(this).hasClass("active")) {
						id += $(this).attr("rec-id") + ',';
					}
				}
			 })
			if(id==''){
				alert('至少选中一个商品');
				return false;
			}
			location.href = 'index.php?c=flow&a=checkout';
		}

		</script>
		
		
		
		
	</body>

</html>